package com.xjrsoft.module.workflow.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.core.secure.XjrUser;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.core.tool.utils.CollectionUtil;
import com.xjrsoft.core.tool.utils.StringPool;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.base.dto.GetPageListDto;
import com.xjrsoft.module.base.entity.XjrBaseAuthorize;
import com.xjrsoft.module.base.entity.XjrBaseModule;
import com.xjrsoft.module.base.entity.XjrBaseUser;
import com.xjrsoft.module.base.service.*;
import com.xjrsoft.module.base.utils.OrganizationCacheUtil;
import com.xjrsoft.module.form.service.IXjrFormSchemeInfoService;
import com.xjrsoft.module.form.service.IXjrFormSchemeService;
import com.xjrsoft.module.workflow.dto.NwfRelationDto;
import com.xjrsoft.module.workflow.entity.XjrNwfRelation;
import com.xjrsoft.module.workflow.entity.XjrNwfSchemeinfo;
import com.xjrsoft.module.workflow.mapper.XjrNwfRelationMapper;
import com.xjrsoft.module.workflow.service.IXjrNwfRelationService;
import com.xjrsoft.module.workflow.service.IXjrNwfSchemeInfoService;
import com.xjrsoft.module.workflow.service.IXjrNwfSchemeService;
import com.xjrsoft.module.workflow.vo.NwfRelationVo;
import io.jsonwebtoken.lang.Collections;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class XjrNwfRelationServiceImpl extends ServiceImpl<XjrNwfRelationMapper, XjrNwfRelation> implements IXjrNwfRelationService {

    RepositoryService repositoryService;

    IXjrBaseModuleService moduleService;

    IXjrNwfSchemeInfoService nwfSchemeInfoService;

    IXjrNwfSchemeService nwfSchemeService;

    IXjrBaseTempfieldService tempService;

    IXjrFormSchemeService formSchemeService;

    IXjrFormSchemeInfoService formSchemeInfoService;

    IXjrBaseAuthorizeService authorizeService;

    IXjrBaseUserRelationService userRelationService;

    IXjrBaseUserService userService;

    XjrNwfRelationMapper relationMapper;

    @Override
    public JSONArray getNwfSchemeInfoIds(String idValue) {
        JSONArray definitionKeys = new JSONArray();
        if (idValue != null) {
            XjrNwfRelation xjrNwfRelation = getById(idValue);
            if (xjrNwfRelation != null) {
                JSONObject jsonObject = JSON.parseObject(xjrNwfRelation.getSettingJson());
                JSONArray stepArrays = jsonObject.getJSONArray("step2");
                ArrayList<String> nwfSchemeInfoIds = new ArrayList<>();
                for (int i = 0; i < stepArrays.size(); i++) {
                    nwfSchemeInfoIds.add(stepArrays.getJSONObject(i).getString("F_Id"));
                }
                List<XjrNwfSchemeinfo> xjrNwfSchemeinfos = nwfSchemeInfoService.listByIds(nwfSchemeInfoIds);
                for (int i = 0; i < stepArrays.size(); i++) {
                    JSONObject nwfSchemeInfoObj = stepArrays.getJSONObject(i);
                    String nwfSchemeInfoId = nwfSchemeInfoObj.getString("F_Id");
                    XjrNwfSchemeinfo xjrNwfSchemeinfo = xjrNwfSchemeinfos.stream().filter(s -> s.getId().equals(nwfSchemeInfoId)).findAny().orElse(null);
                    if (xjrNwfSchemeinfo != null) {
                        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(xjrNwfSchemeinfo.getDeploymentId()).singleResult();
                        definitionKeys.add(processDefinition.getKey());
                    }
                }
            }
        }
        return definitionKeys;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/2
     * @Param:[idValue]
     * @return:java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     * @Description:根据主键ID获取设置的表单字段名
     */
    @Override
    public JSONArray getFormFieldById(String idValue) {
        JSONArray retArray = new JSONArray();
        if (StringUtils.isBlank(idValue)) {
            return retArray;
        }
        XjrNwfRelation xjrNwfRelation = getById(idValue);
        if (xjrNwfRelation != null) {
            JSONObject settingJson = JSON.parseObject(xjrNwfRelation.getSettingJson());
            JSONObject formFileldObj = settingJson.getJSONObject("step4");
            if (formFileldObj != null) {
                JSONArray formFilelds = formFileldObj.getJSONArray("fields");
                    for (int i = 0; i < formFilelds.size(); i++) {
                        JSONObject jsonObject = formFilelds.getJSONObject(i);
                        if (jsonObject.size() > 6) {
                            retArray.add(jsonObject);
                        }
                    }
                }
            }
        return retArray;
    }

    @Override
    public JSONArray getSearchFieldById(String idValue,String queryParameter) {
        JSONArray retArray = new JSONArray();
        JSONObject queryParameterJson = JSONObject.parseObject(queryParameter);
        if(queryParameterJson!=null){
        Set<String> keys = queryParameterJson.keySet();
        if (CollectionUtil.isNotEmpty(keys)) {
            if (StringUtils.isBlank(idValue)) {
                return retArray;
            }
            keys = keys.stream().map(s -> {
                if (StringUtil.endsWithIgnoreCase(s, "_End")) {
                    s=s.replace("_End", StringPool.EMPTY);
                } else if (StringUtil.endsWithIgnoreCase(s, "_Start")) {
                    s=s.replace("_Start", StringPool.EMPTY);
                }
                return s;
            }).collect(Collectors.toSet());
            XjrNwfRelation xjrNwfRelation = getById(idValue);
            if (xjrNwfRelation != null) {
                JSONObject settingJson = JSON.parseObject(xjrNwfRelation.getSettingJson());
                JSONArray formFilelds = settingJson.getJSONArray("step5");
                for (int i = 0; i < formFilelds.size(); i++) {
                    JSONObject jsonObject = formFilelds.getJSONObject(i);
                    if (StringUtil.isNotBlank(jsonObject.getString("bindTable"))) {
                        //为自定义的
                        if (keys.contains(jsonObject.getString("name"))) {
                            //是查询条件
                            retArray.add(jsonObject);
                        }
                    }
                }
            }
        }
    }
        return retArray;
    }

    //获取分页信息
    @Override
    public JSONObject getPageInfoById(String idValue) {
        JSONObject retArray =new JSONObject();
        if (StringUtils.isBlank(idValue)) {
            return retArray;
        }
        XjrNwfRelation xjrNwfRelation = getById(idValue);
        if (xjrNwfRelation != null) {
            JSONObject settingJson = JSON.parseObject(xjrNwfRelation.getSettingJson());
            JSONObject formFileldObj = settingJson.getJSONObject("step4");
            String isPage="false";
            String pageSize="";
            if(formFileldObj!=null) {
                isPage = formFileldObj.getString("isPage");
                pageSize = formFileldObj.getString("pageSize");
            }
            retArray.put("isPage",isPage);
            retArray.put("pageSize",pageSize);
        }
        return retArray;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[schemeInfoId]
     * @return:java.util.List<com.xjrsoft.module.workflow.entity.XjrNwfRelation>
     * @Description:根据流程模板信息id获取
     */
    @Override
    public List<XjrNwfRelation> getBySchemeInfoId(String schemeInfoId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("F_SchemeInfoId", schemeInfoId);
        return baseMapper.selectList(query);
    }

    @Override
    public PageOutput<NwfRelationVo> queryNwfRelation(GetPageListDto dto) {
        Page<NwfRelationVo> page = relationMapper.queryNwfRelation(new Page(dto.getLimit(), dto.getSize()), dto.getKeyword());
        return ConventPage.getPageOutput(page);
    }

    @Override
    public String addNwfRelation(NwfRelationDto dto, XjrUser currentUser) {
        XjrBaseModule xjrBaseModule = BeanUtil.copy(dto.getXjrBaseModule(), XjrBaseModule.class);
        XjrNwfRelation xjrNwfRelation = BeanUtil.copy(dto.getXjrNwfRelation(), XjrNwfRelation.class);
        // 专项菜单ID
        String fId ="";
        // 菜单ID
        String moduleId = StringUtil.randomUUID();
        // 配置json
        String fSettingjson = xjrNwfRelation.getSettingJson();
        boolean flag = false;
        if (StringUtils.isNotBlank(fSettingjson)) {
            JSONObject jsonMap = JSON.parseObject(fSettingjson);
            JSONArray nwfSchemeInfo = jsonMap.getJSONArray("step2");
            // 获取流程模板ID
            flag = nwfSchemeInfo.size() > 1 ? true : false;
            // 添加模板权限
        }
        xjrNwfRelation.setCreateDate(LocalDateTime.now());
        xjrNwfRelation.setCreateUserId(currentUser.getUserId());
        xjrNwfRelation.setCreateUserName(currentUser.getUserName());
        xjrNwfRelation.setModuleId(moduleId);
        // flag = true 多个模板
        xjrNwfRelation.setNwfSchemeType(flag ? 2 : 1);
        boolean nwfRelationSave = this.save(xjrNwfRelation);
        if (nwfRelationSave) {
            // 新增菜单
            fId = xjrNwfRelation.getId();
            xjrBaseModule.setModuleId(moduleId);
            xjrBaseModule.setCreateDate(LocalDateTime.now());
            xjrBaseModule.setCreateUserId(currentUser.getUserId());
            xjrBaseModule.setCreateUserName(currentUser.getUserName());
            xjrBaseModule.setDeleteMark(0);
            xjrBaseModule.setEnabledMark(1);
            xjrBaseModule.setIsMenu(1);
            xjrBaseModule.setTarget("iframe");
            xjrBaseModule.setComponent("views/WorkFlow/WFSpecialMenu");
            xjrBaseModule.setUrlAddress("/customSpecialMenu/" + xjrNwfRelation.getNwfRelationCode() + StringPool.SLASH + fId);
             moduleService.save(xjrBaseModule);
        }
        return fId;
    }

    @Override
    public boolean updateNwfRelation(String fId, NwfRelationDto dto, XjrUser currentUser) throws Exception {
        String moduleId = this.getById(fId).getModuleId();
        XjrNwfRelation xjrNwfRelation = BeanUtil.copy(dto.getXjrNwfRelation(), XjrNwfRelation.class);
        XjrBaseModule xjrBaseModule = BeanUtil.copy(dto.getXjrBaseModule(), XjrBaseModule.class);
        xjrBaseModule.setModuleId(moduleId);
        xjrNwfRelation.setId(fId);
        // 流程idlist
        JSONArray nwfSchemeIdList = new JSONArray();
        // 配置json
        String fSettingjson = xjrNwfRelation.getSettingJson();
        boolean flag = false;
        if (StringUtils.isNotBlank(fSettingjson)) {
            JSONObject jsonMap = JSON.parseObject(fSettingjson);
            JSONArray nwfSchemeInfo = jsonMap.getJSONArray("step2");
            if (nwfSchemeInfo.size() > 1) {
                // 获取流程模板ID
                for (int j = 0; j < nwfSchemeInfo.size(); j++) {
                    JSONObject jsonObject = nwfSchemeInfo.getJSONObject(j);
                    String nwfSchemeInfoId = jsonObject.getString("F_Id");
                    nwfSchemeIdList.add(nwfSchemeInfoId);
                }
                flag = true;
            }
        }
        xjrNwfRelation.setNwfSchemeType(flag ? 2 : 1);
        xjrNwfRelation.setModifyDate(LocalDateTime.now());
        xjrNwfRelation.setModifyUserName(currentUser.getUserName());
        xjrNwfRelation.setModifyUserId(currentUser.getUserId());
        if (this.updateById(xjrNwfRelation)) {
            // 菜单更新
            return moduleService.updateById(xjrBaseModule);
        }
        return true;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2021/1/25
     * @Param:[nwfSchemeInfoId]
     * @return:com.alibaba.fastjson.JSONArray
     * @Description:获取流程表单信息
     */
    @Override
    public JSONArray getNwfFormInfo(String nwfSchemeInfoId) {
        JSONArray retArray = new JSONArray();
        // 获取json
        JSONObject jsonObject = nwfSchemeService.getSchemeJsonByInfoId(nwfSchemeInfoId);
        JSONArray childShapes = jsonObject.getJSONArray("childShapes");
        for (int i = 0; i < childShapes.size(); i++) {
            // 节点信息数组
            JSONArray nodeInfoArray = new JSONArray();
            JSONObject childShape = childShapes.getJSONObject(i);
            JSONObject properties = childShape.getJSONObject("properties");
            JSONObject stencil = childShape.getJSONObject("stencil");
            if (properties.containsKey("tableData")) {
                JSONArray tableData = properties.getJSONArray("tableData");
                for (int k = 0; k < tableData.size(); k++) {
                    // 表单信息jsonObject
                    JSONObject FormInfoObj = new JSONObject();
                    JSONObject tableDataObj = tableData.getJSONObject(k);
                    // 节点类型
                    FormInfoObj.put("nodeType", stencil.getString("id"));
                    // 节点名称
                    FormInfoObj.put("nodeName", properties.getString("name"));
                    // 表单名称
                    FormInfoObj.put("formName", tableDataObj.getString("F_Name"));
                    // 表单字段
                    JSONArray children = tableDataObj.getJSONArray("children");
                    Iterator<Object> iterator = children.iterator();
                    while (iterator.hasNext()) {
                        JSONObject next = (JSONObject) iterator.next();
                        if (!next.containsKey("bindTable")) {
                            iterator.remove();
                        }
                    }
                    FormInfoObj.put("children", children);
                    // 节点ID
                    FormInfoObj.put("resourceId", properties.getString("id"));
                    nodeInfoArray.add(FormInfoObj);
                }
                retArray.add(nodeInfoArray);
            }
        }
        return retArray;
    }

    @Override
    public JSONArray getTableFieldList(String nwfSchemeInfoId) {
        JSONArray retArray = new JSONArray();
        JSONObject json = nwfSchemeService.getSchemeJsonByInfoId(nwfSchemeInfoId);
        if (json != null) {
            JSONArray childShapes = json.getJSONArray("childShapes");
            for (int i = 0; i < childShapes.size(); i++) {
                // 节点信息jsonObject
                JSONObject nodeInfoObj = new JSONObject();
                JSONObject childShape = childShapes.getJSONObject(i);
                JSONObject properties = childShape.getJSONObject("properties");
                JSONObject stencil = childShape.getJSONObject("stencil");
                String formkeydefinitionStr = properties.getString("formkeydefinition");
            }
        }
        return retArray;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteNwfRelation(String id) throws Exception {
        XjrNwfRelation xjrNwfRelation = baseMapper.selectById(id);
        if (xjrNwfRelation != null) {
            String moduleId = xjrNwfRelation.getModuleId();
            if (baseMapper.deleteById(id) > 0) {
                // 删除菜单
                return moduleService.removeById(moduleId);
            }
        }
        return false;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2021/2/24
     * @Param:[nwfRelationId, currentUserId]
     * @return:boolean
     * @Description:判断当前用户是否有字段权限
     */
    @Override
    public boolean checkFieldAuthority(String nwfRelationId, String currentUserId, List<XjrBaseUser> xjrBaseUserlist ) {
        XjrNwfRelation xjrNwfRelation = getById(nwfRelationId);
        if (xjrNwfRelation != null) {
            JSONObject settingJson = JSON.parseObject(xjrNwfRelation.getSettingJson());
            JSONObject stepObject = settingJson.getJSONObject("step6");
            if (stepObject != null) {
                JSONArray authorityData = stepObject.getJSONArray("authorityData");
                Integer userType = stepObject.getInteger("userType");
                if (userType == 1) {
                    return true;
                }
                for (int i = 0; i < authorityData.size(); i++) {
                    JSONObject jsonObject = authorityData.getJSONObject(i);
                    Integer objType = Integer.valueOf(jsonObject.getString("F_ObjType"));
                    String objId = jsonObject.getString("F_ObjId");
                    if (objType == 1) {
                        // 岗位
                        List<XjrBaseUser> usersOfPost = userRelationService.getUsersOfObject(objId, 2);
                        for (XjrBaseUser user : usersOfPost) {
                            if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                                return true;
                            }
                        }
                    } else if (objType == 2) {
                        // 角色
                        List<XjrBaseUser> usersOfRole = userRelationService.getUsersOfObject(objId, 1);
                        for (XjrBaseUser user : usersOfRole) {
                            if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                                return true;
                            }
                        }
                    } else {
                        Optional<XjrBaseUser> first = xjrBaseUserlist.stream().filter(x -> x.getUserId().equals(objId)).findFirst();
                        if (first.isPresent()) {
                            XjrBaseUser user = first.get();
                            // 人员
                            if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                                return true;
                            }
                        }
                    }
                }
            } else {
                return true;
            }
        }
        return false;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2021/3/9
     * @Param:[nwfRelationId, currentUserId]
     * @return:boolean: true-有权限访问  false-无权限访问
     * @Description:检查模板权限
     */
    @Override
    public boolean checkTemplateAuthority(String nwfRelationId, String currentUserId) {
        //获取用户信息缓存
        List<XjrBaseUser> xjrBaseUserlist = OrganizationCacheUtil.getListCaches(OrganizationCacheUtil.USER_LIST_CACHE_KEY);
        if (StringUtils.isBlank(nwfRelationId)) {
            return true;
        }
        XjrNwfRelation xjrNwfRelation = getById(nwfRelationId);
        if (xjrNwfRelation != null) {
            JSONObject settingJson = JSON.parseObject(xjrNwfRelation.getSettingJson());
            JSONObject stepObject = settingJson.getJSONObject("step3");
            JSONArray authorityData = stepObject.getJSONArray("authorityData");
            Integer userType = stepObject.getInteger("userType");
            if (userType == 1) {
                return true;
            }
            for (int i = 0; i < authorityData.size(); i++) {
                JSONObject jsonObject = authorityData.getJSONObject(i);
                Integer objType = Integer.valueOf(jsonObject.getString("F_ObjType"));
                String objId = jsonObject.getString("F_ObjId");
                if (objType == 1) {
                    // 岗位
                    List<XjrBaseUser> usersOfPost = userRelationService.getUsersOfObject(objId, 2);
                    for (XjrBaseUser user : usersOfPost) {
                        if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                            return true;
                        }
                    }
                } else if (objType == 2) {
                    // 角色
                    List<XjrBaseUser> usersOfRole = userRelationService.getUsersOfObject(objId, 1);
                    for (XjrBaseUser user : usersOfRole) {
                        if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                            return true;
                        }
                    }
                } else {
                    Optional<XjrBaseUser> xjrBaseUserOptional = xjrBaseUserlist.stream().filter(s -> StringUtil.equals(s.getUserId(), objId)).findFirst();
                    if(xjrBaseUserOptional.isPresent()) {
                        XjrBaseUser user = xjrBaseUserOptional.get();
                        // 人员
                        if (StringUtils.equalsIgnoreCase(user.getUserId(), currentUserId)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[fSettingjson, currentUser, moduleId]
     * @return:boolean
     * @Description:添加模板权限
     */
    public boolean addAuthority(String fSettingjson, XjrUser currentUser, String moduleId) {
        boolean flag = true;
        JSONObject jsonMap = JSON.parseObject(fSettingjson);
        JSONObject step3Obj = jsonMap.getJSONObject("step3");
        JSONArray authorityArray = step3Obj.getJSONArray("authorityData");
        Integer userType = step3Obj.getInteger("userType");
        if (userType == 1) {
            // 所有人都具备权限
            List<XjrBaseUser> allUserList = userService.getAllUserList();
            for (XjrBaseUser xjrBaseUser : allUserList) {
                XjrBaseAuthorize xjrBaseAuthorize = new XjrBaseAuthorize();
                xjrBaseAuthorize.setAuthorizeId(IdWorker.getIdStr());
                xjrBaseAuthorize.setObjectId(xjrBaseUser.getUserId());
                xjrBaseAuthorize.setItemType(1);
                xjrBaseAuthorize.setItemId(moduleId);
                xjrBaseAuthorize.setObjectType(2);
                if (!authorizeService.save(xjrBaseAuthorize)) {
                    return false;
                }
            }
        } else {
            if (!Collections.isEmpty(authorityArray)) {
                for (int i = 0; i < authorityArray.size(); i++) {
                    JSONObject authorityObj = authorityArray.getJSONObject(i);
                    String fId = authorityObj.getString("F_Id");
                    String objType = authorityObj.getString("F_ObjType");
                    String objId = authorityObj.getString("F_ObjId");
                    XjrBaseAuthorize xjrBaseAuthorize = new XjrBaseAuthorize();
                    xjrBaseAuthorize.setAuthorizeId(fId);
                    xjrBaseAuthorize.setObjectId(objId);
                    xjrBaseAuthorize.setItemType(1);
                    xjrBaseAuthorize.setItemId(moduleId);
                    if (StringUtils.equals(objType, "1")) {
                        // 添加岗位权限
                        xjrBaseAuthorize.setObjectType(3);
                    } else if (StringUtils.equals(objType, "2")) {
                        // 添加角色权限
                        xjrBaseAuthorize.setObjectType(1);
                    } else if (StringUtils.equals(objType, "3")) {
                        // 添加用户权限
                        xjrBaseAuthorize.setObjectType(2);
                    }
                    flag = authorizeService.save(xjrBaseAuthorize);
                }
            }
        }
        return flag;
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[fId]
     * @return:boolean
     * @Description:删除用户权限
     */
    private boolean deleteAuthority(String fId) {
        XjrNwfRelation xjrNwfRelation = getById(fId);
        if (xjrNwfRelation != null) {
            String fSettingjson = xjrNwfRelation.getSettingJson();
            JSONObject jsonMap = (JSONObject) JSON.parse(fSettingjson);
            JSONArray authorityArray = (JSONArray) jsonMap.get("step5");
            for (int i = 0; i < authorityArray.size(); i++) {
                JSONObject authorityObj = authorityArray.getJSONObject(i);
                String objType = authorityObj.getString("F_ObjType");
                if (StringUtils.equals(objType, "1")) {
                    // 添加岗位权限
                    objType = "3";
                } else if (StringUtils.equals(objType, "2")) {
                    // 添加角色权限
                    objType = "1";
                } else if (StringUtils.equals(objType, "3")) {
                    // 添加用户权限
                    objType = "2";
                }
                String id = authorityObj.getString("F_Id");
                XjrBaseAuthorize xjrBaseAuthorize = authorizeService.getById(id);
                if (xjrBaseAuthorize != null) {
                    boolean delete = authorizeService.removeById(xjrBaseAuthorize.getAuthorizeId());
                    if (!delete) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

}


